//
//  NodataCollectionCell.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/14.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "NodataCollectionCell.h"
#import "StateProgress.h"
#import "config.h"
#import "StringTool.h"
@interface NodataCollectionCell ()
@property (nonatomic,retain)StateProgress *progressBar;
@end


@implementation NodataCollectionCell
@synthesize progressBar,refreshBtn;


-(instancetype)initWithFrame:(CGRect)frame WithCollectionView:(UICollectionView *)collectionView
{

    if (self = [super initWithFrame:frame])
    {
        UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [bg setBackgroundColor:[UIColor colorWithRed:(float)0xf7/(float)0xff green:(float)0xf7/(float)0xff blue:(float)0xf7/(float)0xff alpha:1.0f]];
        [self setBackgroundView:bg];
        
        
        progressBar = [[StateProgress alloc]initWithFrame:CGRectMake(10, frame.size.height/2-50/2,frame.size.width-20, 50)];
        [progressBar setProgressImg:@"loding_bar" withBackImg:@"loding_out"];
        [self addSubview:progressBar];
        
        UIImage *img = [UIImage imageNamed:@"btn_ref"];
        refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [refreshBtn setBackgroundColor:[UIColor clearColor]];
        [refreshBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [refreshBtn.titleLabel setFont:[UIFont systemFontOfSize:15.0f]];
        [refreshBtn setTitle:@"立即刷新" forState:UIControlStateNormal];
        [refreshBtn setBackgroundImage:img forState:UIControlStateNormal];
        [refreshBtn setBackgroundImage:[UIImage imageNamed:@"btn_ref_se"] forState:UIControlStateHighlighted];
        
        [refreshBtn setFrame:CGRectMake(frame.size.width/2-img.size.width/2, progressBar.frame.size.height+progressBar.frame.origin.y, img.size.width, img.size.height)];
        [self addSubview:refreshBtn];
        [self setUserInteractionEnabled:YES];
        [refreshBtn setUserInteractionEnabled:YES];

    }
    return self;
}


-(void)setState:(nodataCollectionCellState)_state
{
    if (_state==nodataCollectionCellStateLoading) {
        NSLog(@"------------LLLLLL");
        [progressBar loadData];
        refreshBtn.hidden = YES;
    }else if(_state == nodataCollectionCellStateNodata){
        NSLog(@"------------NNNNNNN");
        [progressBar noData];
        refreshBtn.hidden = YES;
    }else if (_state==nodataCollectionCellStateNetError){
        
        [progressBar netError];
        refreshBtn.hidden = NO;
    }else if(_state==nodataCollectionCellStateNorMal){
        [self setState:nodataCollectionCellStateLoading];
    }
}



-(void)setCodeErrorTip:(NSString*)code{
    if (![StringTool isBlankString:code]) {
        code = [NSString stringWithFormat:@"%@:",code];
    }else{
        code = @"";
    }
    [self setCustTip:[NSString stringWithFormat:@"网络出错%@",code]];
}


-(void)setCustTip:(NSString*)tip{
    refreshBtn.hidden = false;
    [progressBar setCustTip:tip];
}


-(void)setCustBtnTip:(NSString*)tip{
    
    refreshBtn.hidden = false;
    [refreshBtn setTitle:tip forState:UIControlStateNormal];
}




@end
